package com.gitee.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gitee.mapper.CommentMapper;
import com.gitee.pojo.Comment;
import com.gitee.pojo.OrderItem;
import com.gitee.service.ICommentService;
import com.gitee.vo.CommentVo;
import com.gitee.vo.PageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class CommentServiceImpl extends ServiceImpl<CommentMapper, Comment> implements ICommentService {

    @Autowired
    private CommentMapper commentMapper;

    /**
     * 评论列表
     * @param keywords
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public PageVo<CommentVo> pageCommentVos(String keywords, Integer pageNum, Integer pageSize) {
        IPage<CommentVo> commentVoIPage = commentMapper.selectCommentVos(new Page<>(pageNum, pageSize), keywords);
        return new PageVo<>(commentVoIPage.getRecords(), (int) commentVoIPage.getTotal());
    }

    @Transactional
    @Override
    public Boolean deleteByOrderIds(List<Integer> orderIds) {
        LambdaUpdateWrapper<Comment> updateWrapper = new UpdateWrapper<Comment>().lambda()
                .in(!CollectionUtil.isEmpty(orderIds), Comment::getOrderId, orderIds);
        return super.remove(updateWrapper);
    }
}
